package com.example.mydemo;

import android.accounts.AbstractAccountAuthenticator;
import android.accounts.Account;
import android.accounts.AccountAuthenticatorResponse;
import android.accounts.AccountManager;
import android.accounts.NetworkErrorException;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

public class MyAuthenticator extends AbstractAccountAuthenticator {
    private Context mContext;
    public MyAuthenticator(Context context) {
        super(context);
        mContext = context;
    }

    @Override
    public Bundle editProperties(AccountAuthenticatorResponse r, String s) {
        return null;
    }

    @Override
    public Bundle addAccount(AccountAuthenticatorResponse r, String s, String s2, String[] strings,
                             Bundle bundle) throws NetworkErrorException {
        Log.d("lfy","[MyAuthenticator] addAccount......");
        Bundle b = new Bundle();
        Intent i = new Intent(mContext, MainActivity.class);
        b.putParcelable(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, r);//回调
        b.putParcelable(AccountManager.KEY_INTENT, i);
        return b;


//        final Bundle result = new Bundle();
//        result.putString(AccountManager.KEY_ACCOUNT_NAME, "Test Account");
//        result.putString(AccountManager.KEY_ACCOUNT_TYPE, s);
//        return result;
    }

    @Override
    public Bundle confirmCredentials(AccountAuthenticatorResponse r, Account account, Bundle bundle)
            throws NetworkErrorException {
        Log.d("lfy","[MyAuthenticator] confirmCredentials......");
        return null;
    }

    @Override
    public Bundle getAuthToken(AccountAuthenticatorResponse r, Account account, String s,
                               Bundle bundle) throws NetworkErrorException {
        Log.d("lfy","[MyAuthenticator] getAuthToken......");
        return null;
    }

    @Override
    public String getAuthTokenLabel(String s) {
        return s;
    }

    @Override
    public Bundle updateCredentials(AccountAuthenticatorResponse r, Account account, String s,
                                    Bundle bundle) throws NetworkErrorException {
        Log.d("lfy","[MyAuthenticator] updateCredentials......");
        return null;
    }

    @Override
    public Bundle hasFeatures(AccountAuthenticatorResponse r, Account account, String[] strings)
            throws NetworkErrorException {
        Log.d("lfy","[MyAuthenticator] hasFeatures......");
        return null;
    }
}
